home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-19 | 2.9 KB | 126 lines | [TEXT/CWIE] |
- //
- // You may incorporate this sample code into your
- // applications without restriction. This sample code has
- // been provided "AS IS" and the responsibility for its
- // operation is 100% yours. You are not permitted to
- // redistribute the source as "Apple sample code" after
- // having made changes. If you're going to re-distribute
- // the source, we require that you make it clear in the
- // source that the code was descended from Apple sample
- // code, but that you've made changes.
- //
-
- #define OLDROUTINELOCATIONS 0
- #define OLDROUTINENAMES 0
- #define SystemSevenOrLater 1
-
- #ifndef __FONTS__
- # include <Fonts.h>
- #endif
-
- #ifndef __DIALOGS__
- # include <Dialogs.h>
- #endif
-
- #ifndef __QDOFFSCREEN__
- # include <QDOffscreen.h> // for CTabChanged
- #endif
-
- #include "MoveableModalDialog.h"
-
- enum
- {
- kDialogItemIndex_DrawButton = 3,
- kDialogItemIndex_CheckBox
- };
-
- static pascal OSErr InitMac (void)
- {
- MaxApplZone ( );
- InitGraf (&(qd.thePort));
- InitFonts ( );
- InitWindows ( );
- InitMenus ( );
- TEInit ( );
- InitDialogs (nil);
-
- return noErr;
- }
-
- static pascal OSErr Draw1ControlWithBackgroundColor (ControlRef controlRef, const RGBColor *rgb)
- {
- //
- // This function walks the color table of the given control's
- // window looking for the content color. If it finds such a color,
- // it replaces it with the given color momentarily while drawing
- // the given control.
- //
-
- OSErr err = noErr;
-
- AuxWinHandle auxWinHandle;
- WindowRef contrlOwner = (**controlRef).contrlOwner;
- Boolean oldColorTableWasDefault = GetAuxWin (contrlOwner,&auxWinHandle);
- WCTabHandle winCTabHandle = (WCTabHandle) ((**auxWinHandle).awCTable);
- short ctIndex = (**winCTabHandle).ctSize;
-
- while (ctIndex > -1)
- {
- ColorSpecPtr rgbScan = ctIndex + (**winCTabHandle).ctTable;
-
- if (rgbScan->value == wContentColor)
- {
- RGBColor savedRGB = rgbScan->rgb;
- rgbScan->rgb = *rgb;
- CTabChanged ((CTabHandle) winCTabHandle);
- Draw1Control (controlRef);
- // assume memory has moved and rgbScan has become stale
- (**winCTabHandle).ctTable [ctIndex].rgb = savedRGB;
- CTabChanged ((CTabHandle) winCTabHandle);
- return noErr; // loop never exits
- }
-
- --ctIndex;
- }
-
- // if the loop has exited, we didn't find the content color
-
- Draw1Control (controlRef);
-
- return err;
- }
-
- void main (void)
- {
- if (InitMac ( ))
- SysBeep (10);
- else
- {
- DialogRef dlgRef = GetNewDialog (129,nil,(WindowRef)-1);
- if (dlgRef)
- {
- short itemHit;
-
- SetDialogDefaultItem (dlgRef,kStdOkItemIndex);
-
- do
- {
- MoveableModalDialog (StdFilterProc,&itemHit);
-
- if (itemHit == kDialogItemIndex_DrawButton)
- {
- short iType; Handle iHandle; Rect iRect;
- RGBColor blue = { 0,0,0xFFFF };
-
- GetDialogItem (dlgRef,kDialogItemIndex_CheckBox,&iType,&iHandle,&iRect);
- if (Draw1ControlWithBackgroundColor ((ControlRef)iHandle, &blue))
- SysBeep (10);
- }
- }
- while (itemHit != kStdOkItemIndex);
-
- DisposeDialog (dlgRef);
- }
- }
- }
-